package com.wenhao.netease.game;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-08-07 19:30
 */
public class Main1 {

    private static int[] mul = new int[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    private static Map<Character,Integer> map = new HashMap<>();
    private static int count;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        map.put('1',0);
        map.put('0',1);
        map.put('X',2);
        map.put('9',3);
        map.put('8',4);
        map.put('7',5);
        map.put('6',6);
        map.put('5',7);
        map.put('4',8);
        map.put('3',9);
        map.put('2',10);
        for (int i = 0;i < T;i++) {
            count = 0;
            String code = scanner.next();
            int sum = 0;
            for (int j = 0;j < 14;j++) {
                sum += (code.charAt(j) - '0') * mul[j];
            }
            getCount(14,sum,code);
            System.out.println(count);
        }
    }

    private static void getCount(int index,int sum,String code) {
        if (index == 17) {
            if (sum % 11 == map.get(code.charAt(17))) {
                count++;
            }
            return;
        }
        if (code.charAt(index) == '*') {
            for (int i = 0;i < 10;i++) {
                getCount(index + 1,sum + i * mul[index],code);
            }
        } else {
            getCount(index + 1,sum + (code.charAt(index) - '0') * mul[index],code);
        }
    }
}
